package com.pignest.hotel.system;

import org.zkoss.zk.ui.util.Clients;

import com.pignest.framework.util.Utils;
import com.pignest.hotel.beans.HotelBill;
import com.pignest.hotel.beans.User;
import com.pignest.hotel.definition.BillType;
import com.pignest.hotel.definition.OpenRoomType;
import com.pignest.hotel.definition.PayMethod;
import com.pignest.hotel.util.DateUtil;
import com.pignest.hotel.util.UIUtils;

public class Print {

	/**
	 * @param printState 0 打印 1 查看 2设计
	 *        
	 * */
	public static String hotelName =com.pignest.hotel.system.Config.getHotelName();
	public static int billTemplates=com.pignest.hotel.system.Config.getDefaultBillTemplates();
	public static void printCheck(HotelBill b,String printState)
	{
		String s =Hotel.showMoneySymbol;

		String orderNo =b.getOrderNo();
		String roomName =b.getRoomName();
		String roomType =b.getRoomType();
		String nameType =BillType.valueOf(b.getType()).getCname();
		int adjustPrice =b.getAdjustPrice();
		String discount =s+Utils.toPrice(adjustPrice);
		String name =b.getName();
		String sLiveTime=DateUtil.toString(b.getLiveTime(),"yyyy-MM-dd HH:mm:ss");
		float count =b.getLiveCount();
		String open =b.getOpenType();
		String sCount ="";
		if(OpenRoomType.HOURS.name().equals(open))
		{
			sCount=count+"小时";
		}else{
			sCount =count+"天";
		}
		
		String deposit =s+Utils.toPrice(b.getDeposit());
		String sLeaveTime =DateUtil.toString(b.getLeaveTime(),"yyyy-MM-dd HH:mm:ss");
		if(sLeaveTime==null)
			sLeaveTime="未离店";
		String sRent =s+Utils.toPrice(b.getRent());
		String sCost =s+Utils.toPrice(b.getCost());
		String sAccounts =s+Utils.toPrice(b.getAccounts());
		String sRefundment =s+Utils.toPrice(b.getRefundment());
		String paymentMethod=PayMethod.valueOf(b.getPayment()).getDisplayName();
        String userName =b.getOperator();
        String curTime =DateUtil.toString(b.getOpTime(), DateUtil.HOTEL_DEFAULT_FORMAT);
        String oType =OpenRoomType.valueof(b.getOpenType()).getDisplayName();
        String repairCost =s+Utils.toPrice(b.getReparation());
        String clearCost =s+Utils.toPrice(b.getService());
        switch(billTemplates){
           case 1:
        	   Clients.evalJavaScript("check('"+hotelName+"','"+nameType+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+discount+"','"+name+"','"+sLiveTime+"','"+sCount+"','"
       				+deposit+"','"+sLeaveTime+"','"+sRent+"','"+sCost+"','"+sAccounts+"','"+sRefundment+"','"+paymentMethod+"','"+userName+"','"
       				+oType+"','"+clearCost+"','"+repairCost+"','"+curTime+"','"+printState+"');");
           case 2:
        	   Clients.evalJavaScript("check2('"+hotelName+"','"+nameType+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+discount+"','"+name+"','"+sLiveTime+"','"+sCount+"','"
       				+deposit+"','"+sLeaveTime+"','"+sRent+"','"+sCost+"','"+sAccounts+"','"+sRefundment+"','"+paymentMethod+"','"+userName+"','"
       				+oType+"','"+clearCost+"','"+repairCost+"','"+curTime+"','"+printState+"');");
           default:
        	   break;
        }
		
		
	}
	public static void printPartCheck(HotelBill b,String printState){
		String s =Hotel.showMoneySymbol;
		String orderNo =b.getOrderNo();
		String roomName =b.getRoomName();
		String roomType =b.getRoomType();
		String nameType =BillType.valueOf(b.getType()).getCname();
		int adjustPrice =b.getAdjustPrice();
		String discount =s+Utils.toPrice(adjustPrice);
		String name =b.getName();
		String sLiveTime=DateUtil.toString(b.getLiveTime(),"yyyy-MM-dd HH:mm:ss");
		float count =b.getLiveCount();
		String open =b.getOpenType();
		String sCount ="";
		if(OpenRoomType.HOURS.name().equals(open))
		{
			sCount=count+"小时";
		}else{
			sCount =count+"天";
		}
		
		String deposit =s+Utils.toPrice(b.getDeposit());
		String sLeaveTime =DateUtil.toString(b.getLeaveTime(),"yyyy-MM-dd HH:mm:ss");
		if(sLeaveTime==null)
			sLeaveTime="未离店";
		String sRent =s+Utils.toPrice(b.getRent());
		String sCost =s+Utils.toPrice(b.getCost());
		String sAccounts =s+Utils.toPrice(b.getAccounts());
		String sRefundment =s+Utils.toPrice(b.getRefundment());
		String paymentMethod=PayMethod.valueOf(b.getPayment()).getDisplayName();
        String userName =b.getOperator();
        String curTime =DateUtil.toString(b.getOpTime(), DateUtil.HOTEL_DEFAULT_FORMAT);
        String oType =OpenRoomType.valueof(b.getOpenType()).getDisplayName();
        String repairCost =s+Utils.toPrice(b.getReparation());
        String clearCost =s+Utils.toPrice(b.getService());
        switch(billTemplates){
          case 1:
        	Clients.evalJavaScript("checkPart('"+hotelName+"','"+nameType+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+discount+"','"+name+"','"+sLiveTime+"','"+sCount+"','"
				+deposit+"','"+sLeaveTime+"','"+sRent+"','"+sCost+"','"+sAccounts+"','"+sRefundment+"','"+paymentMethod+"','"+userName+"','"
				+oType+"','"+clearCost+"','"+repairCost+"','"+curTime+"','"+printState+"');");
          case 2:
        	Clients.evalJavaScript("checkPart2('"+hotelName+"','"+nameType+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+discount+"','"+name+"','"+sLiveTime+"','"+sCount+"','"
      				+deposit+"','"+sLeaveTime+"','"+sRent+"','"+sCost+"','"+sAccounts+"','"+sRefundment+"','"+paymentMethod+"','"+userName+"','"
      				+oType+"','"+clearCost+"','"+repairCost+"','"+curTime+"','"+printState+"');"); 
          default:
       	   break;
        }
	}
	public static void printLiving(HotelBill b,String printState)
	{
		if(b==null)
			return ;
		String s =Hotel.showMoneySymbol;
		String orderNo =b.getOrderNo();
		String roomName =b.getRoomName();
		String roomType =b.getRoomType();
		int adjustPrice =b.getAdjustPrice();
		String discount =s+Utils.toPrice(adjustPrice);
		String sLiveTime=DateUtil.toString(b.getLiveTime(),"yyyy-MM-dd HH:mm:ss");
		String deposit =s+Utils.toPrice(b.getDeposit());
		String cerType =b.getCerType();
		String cerNo =b.getCerNo();
		String roomPrice =s+Utils.toPrice(b.getRoomPrice());
		String oType =OpenRoomType.valueof(b.getOpenType()).getDisplayName();
		String name =b.getName();
	
		String userName =b.getOperator();
		
		String curTime =DateUtil.toString(b.getOpTime(), DateUtil.HOTEL_DEFAULT_FORMAT);
		 switch(billTemplates){
         case 1:
	        	 Clients.evalJavaScript("livingPrint('"+hotelName+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+discount+"','"+name+"','"+sLiveTime+"','"
					+deposit+"','"+cerType+"','"+cerNo+"','"+userName+"','"+curTime+"','"+roomPrice+"','"+oType+"','"+printState+"');");
         case 2:
        	     Clients.evalJavaScript("livingPrint2('"+hotelName+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+discount+"','"+name+"','"+sLiveTime+"','"
 					+deposit+"','"+cerType+"','"+cerNo+"','"+userName+"','"+curTime+"','"+roomPrice+"','"+oType+"','"+printState+"');");
         default:
        	 break;
		 }
	}
	public static void printComeOn(HotelBill b,String printState){
		String s =Hotel.showMoneySymbol;
		String orderNo =b.getOrderNo();
		String roomName =b.getRoomName();
		String roomType =b.getRoomType();
		String name =b.getName();
		String sLiveTime=DateUtil.toString(b.getLiveTime(),"yyyy-MM-dd HH:mm:ss");
		String deposit =s+Utils.toPrice(b.getDeposit());
		User user =Hotel.getCurrentUser();
		String userName =user.getName();
		String id =b.getId();
		String curTime =DateUtil.toString(b.getOpTime(), DateUtil.HOTEL_DEFAULT_FORMAT);
		switch(billTemplates){
			case 1:
				Clients.evalJavaScript("comeOnPrint('"+hotelName+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+name+"','"+sLiveTime+"','"
						+deposit+"','"+userName+"','"+curTime+"','"+id+"','"+printState+"');");
			case 2:
				Clients.evalJavaScript("comeOnPrint2('"+hotelName+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+name+"','"+sLiveTime+"','"
						+deposit+"','"+userName+"','"+curTime+"','"+id+"','"+printState+"');");	
			default:
		      	   break;
		}
	}
	public static void printChange(HotelBill b,String printState)
	{
		String s =Hotel.showMoneySymbol;
		String orderNo =b.getOrderNo();
		String roomName =b.getRoomName();
		String roomType =b.getRoomType();
		String name =b.getName();
		String sLiveTime=DateUtil.toString(b.getLiveTime(),"yyyy-MM-dd HH:mm:ss");
		String price =s+Utils.toPrice(b.getAccounts());
		String userName =b.getOperator();
		String oldRoomName =b.getOldRoomName();
		String remark =b.getRemark();
		//String curTime =DateUtil.currentDateToString("yyyy-MM-dd HH:mm:ss");
		String curTime =DateUtil.toString(b.getOpTime(), DateUtil.HOTEL_DEFAULT_FORMAT);
		String id =b.getId();
		String roomPrice =s+Utils.toPrice(b.getRoomPrice());
		switch(billTemplates){
				case 1:
					Clients.evalJavaScript("changeRoomPrint('"+hotelName+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+name+"','"+sLiveTime+"','"
							+price+"','"+userName+"','"+curTime+"','"+oldRoomName+"','"+remark+"','"+id+"','"+roomPrice+"','"+printState+"');");
				case 2:
					Clients.evalJavaScript("changeRoomPrint2('"+hotelName+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+name+"','"+sLiveTime+"','"
							+price+"','"+userName+"','"+curTime+"','"+oldRoomName+"','"+remark+"','"+id+"','"+roomPrice+"','"+printState+"');");
				default:
			      	  break;
		}
		
	}
	public static void printCancel(HotelBill b,String printState)
	{
		String s =Hotel.showMoneySymbol;
		String orderNo =b.getOrderNo();
		String roomName =b.getRoomName();
		String roomType =b.getRoomType();
		String name =b.getName();
		String sLiveTime=DateUtil.toString(b.getLiveTime(),"yyyy-MM-dd HH:mm:ss");
		String price =s+Utils.toPrice(b.getAccounts());
		String userName =b.getOperator();
		//String curTime =DateUtil.currentDateToString("yyyy-MM-dd HH:mm:ss");
		String curTime =DateUtil.toString(b.getOpTime(), DateUtil.HOTEL_DEFAULT_FORMAT);
		String id =b.getId();
		String roomPrice =s+Utils.toPrice(b.getRoomPrice());
		switch(billTemplates){
			case 1:
			Clients.evalJavaScript("cancelPrint('"+hotelName+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+name+"','"+sLiveTime+"','"
					+price+"','"+userName+"','"+curTime+"','"+id+"','"+roomPrice+"','"+printState+"');");
			case 2:
				Clients.evalJavaScript("cancelPrint2('"+hotelName+"','"+orderNo+"','"+roomName+"','"+roomType+"','"+name+"','"+sLiveTime+"','"
						+price+"','"+userName+"','"+curTime+"','"+id+"','"+roomPrice+"','"+printState+"');");
			default:
		      	   break;
		}
	}
}
